package com.blazingredfireball.rouleurlog.util
{
	import mx.utils.ObjectUtil;
	import com.blazingredfireball.rouleurlog.model.RouleurlogModelLocator;
	import com.blazingredfireball.rouleurlog.vo.RouteVO;
	import com.blazingredfireball.rouleurlog.vo.BikeVO;
	
	public class ValueObjectUtil
	{
	  
	  private static var model : RouleurlogModelLocator = RouleurlogModelLocator.getInstance();
		
		public static function updateAttributes(valueObject:Object, object:Object):void
		{
			var attributes:Array = ObjectUtil.getClassInfo(object).properties;
			
			for each (var attribute:String in attributes)
			{
				if ( valueObject.hasOwnProperty (attribute) )
					valueObject[attribute] = object[attribute]
			}			
		}
		
		public static function getRouteById(id:int):RouteVO
		{
		  var result:RouteVO = null;
		  for each (var route:RouteVO in model.routes)
		  {
		    if (route.id == id) result = route;
		  }
		  return result;
		} 
		
		public static function getBikeById(id:int):BikeVO
		{
		  var result:BikeVO = null;
		  for each (var bike:BikeVO in model.bikes)
		  {
		    if (bike.id == id) result = bike;
		  }
		  return result;
		} 
	}
}